package com.cg.config;

import com.cg.context.UserContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//@ConditionalOnBean(MyCustomFilter.class)
@Slf4j
//@Order(Integer.MIN_VALUE)
@Component
public class CustomizeHeaderInterceptor extends HandlerInterceptorAdapter {

    private static final String FORBIDDEN_URL = "asyncTest";

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
//        UserContext.clear();
        if (!request.getRequestURI().contains(FORBIDDEN_URL)) {
            UserContext.clear();
            log.info("主线程 {} 清除ThreadLocal", Thread.currentThread().getName());
        }

    }
}
